package com.campus.service.Impl;

import com.campus.dao.RoleDao;
import com.campus.pojo.SysModule;
import com.campus.pojo.SysRole;
import com.campus.service.RoleService;
import com.campus.tools.Tree;
import com.campus.tools.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleDao dao;

    @Override
    public List<SysRole> getAllRole(Map<String, Object> params) {
        return dao.getAllRole(params);
    }

    @Override
    public int count(Map<String, Object> params) {
        return dao.count(params);
    }

    @Override
    public List<Tree> getModules() {
        return dao.getModules();
    }

    @Override
    public List<Tree> getModulesByRole(String roleCode) {
        return dao.getModulesByRole(roleCode);
    }

    @Override
    public int deleteRoleModules(String roleCode, String moduleCode) {
        return dao.deleteRoleModules(roleCode,moduleCode);
    }

    @Override
    public int addRoleModules(String rmId,String roleCode,String moduleCode,String areaId) {
        Map<String,Object> params = new HashMap<>();
        params.put("rmId",rmId);
        params.put("roleCode",roleCode);
        params.put("moduleCode",moduleCode);
        params.put("areaId",areaId);
        return dao.addRoleModules(params);
    }

    @Override
    public String isExistName(String name, String id, String areaId) {
        String result;
        int i = dao.isExistName(name, id, areaId);
        if (i > 0) {
            result = "exit";
        } else {
            result = "no";
        }
        return result;
    }

    @Override
    public int addRole(String rname, String areaId) {
        return dao.addRole(UUIDGenerator.getUUID(), rname, areaId);
    }

    @Override
    public int upRole(SysRole role) {
        return dao.upRole(role.getRoleName(), role.getRoleCode());
    }

    @Override
    public int delRole(String roleCode) {
        return dao.delRole(roleCode);
    }

}
